const Base = require('./base.js');

module.exports = class extends Base {
	constructor(ctx) {
		super(ctx);
		this.score = this.model("system/score");
		this.asset = this.model("system/asset");
	}
	async indexAction() {
		if(this.isGet) {
			return this.display();
		}

		let posts = this.post();
		
		let where = {};
		
		if(!think.isEmpty(posts.type)) {
			where.type = posts.type;
		}
		if(!think.isEmpty(posts.status)) {
			where['m.status'] = posts.status;
		}
		if(!think.isEmpty(posts.change)) {
			where.change = posts.change;
		}
		let fields = "id, type, create_time, score, balance, note, status, change, user_id";
		const data = await this.score.joinUserTable(posts,where,fields);
		return this.json(data);

	}


async deleteAction() {

		let id = this.post("id");
		let rows = await this.score.where({
			id: id
		}).delete();
		if(rows == 0) {
			return this.fail("删除失败");
		}
		return this.success("删除成功");

	}
	
};